namespace ContribSample.jQueryUI
{
	using jQueryApi;
	using Script.Contrib.jQueryUI;
	using System.Collections;

	public class DraggableSamples
	{
		public static void DefaultFunctionality()
		{
			jQueryUI.Select("#draggable").Draggable();
		}

		public static void Events()
		{
			jQueryUIObject draggable = jQueryUI.Select("#draggable").Draggable();
			jQueryObject start_counter = jQuery.Select("#event-start");
			jQueryObject drag_counter = jQuery.Select("#event-drag");
			jQueryObject stop_counter = jQuery.Select("#event-stop");

			int[] counts = new int[] { 0, 0, 0 };

			draggable.Bind("dragstart", delegate(jQueryEvent e, Dictionary ui)
			{
				counts[0]++;
				UpdateCounterStatus(start_counter, counts[0]);
			});

			draggable.Bind("drag", delegate(jQueryEvent e, Dictionary ui)
			{
				counts[1]++;
				UpdateCounterStatus(drag_counter, counts[1]);
			});

			draggable.Bind("dragstop", delegate(jQueryEvent e, Dictionary ui)
			{
				counts[2]++;
				UpdateCounterStatus(stop_counter, counts[2]);
			});
		}

		private static void UpdateCounterStatus(jQueryObject eventCounter, int newCount)
		{
			if (!eventCounter.HasClass("ui-state-hover"))
				eventCounter.AddClass("ui-state-hover").Siblings().RemoveClass("ui-state-hover");

			eventCounter.Find("span.count").Text(newCount.ToString());
		}

		public static void ConstrainMovement()
		{
			jQueryUI.Select("#draggable").Draggable(new Dictionary("axis", "y"));
			jQueryUI.Select("#draggable2").Draggable(new Dictionary("axis", "x"));
			jQueryUI.Select("#draggable3").Draggable(new Dictionary("containment", "#containment-wrapper", "scroll", false));
			jQueryUI.Select("#draggable4").Draggable(new Dictionary("containment", ".draggable-constrain-movement"));
			jQueryUI.Select("#draggable5").Draggable(new Dictionary("containment", "parent"));
		}

		public static void DelayStart()
		{
			jQueryUI.Select("#draggable").Draggable();
		}

		public static void SnapToElementOrGrid()
		{
			jQueryUI.Select("#draggable").Draggable();
		}

		public static void AutoScroll()
		{
			jQueryUI.Select("#draggable").Draggable();
		}

		public static void RevertPosition()
		{
			jQueryUI.Select("#draggable").Draggable();
		}

		public static void VisualFeedback()
		{
			jQueryUI.Select("#draggable").Draggable();
		}

		public static void DragHandle()
		{
			jQueryUI.Select("#draggable").Draggable();
		}

		public static void CursorStyle()
		{
			jQueryUI.Select("#draggable").Draggable();
		}

		public static void DraggableAndSortable()
		{
			jQueryUI.Select("#draggable").Draggable();
		}
	}
}
